local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)

local ok, err = red:connect("101.132.36.174",6379)
if not ok then
    ngx.say("failed to connect: ",err)
    return
end

local res, err = red:auth("rainhowchan")
if not res then
    ngx.say("failed to authenticate: ", err)
    return
end

--[[
local count
count, err = red:get_reused_times()
if 0 == count then
  ok,err = red:auth("rainhowchan")
  if not ok then
    ngx.say("failed to authenticate: ",err)
    return
  end
elseif err then
  ngx.say("failed to reused times: ",err)
  return
end
]]--
local ok, err = red:eval([[
  local info = redis.call('get', KEYS[1])
  return info
]], 1, 'binance.CDTUSDT')

-- ok,err = red:get('binance.CDTUSDT')
if not ok then
  ngx.say('failed to get binance.CDTUSDT ', err)
  return
else  
  ngx.say('binance.CDTUSDT: ', ok)
end

-- ok, err = red:set("dog","an animal")
-- if not ok then
--     ngx.say("failed to set dog: ",err)
--     return
-- end

-- ngx.say("set result: ",ok)

-- local res,err = red:get("dog")
-- if not res then
--     ngx.say("failed to get dog: ",err)
--     return
-- end

-- if res == ngx.null then
--     ngx.say("dog not found.")
--     return
-- end